<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>物资明细</title>
<style type="text/css">
.info_dialog .content_container .content_table tr td input[type="checkbox"] {
	width: auto;
}
</style>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">物资明细列表</div>
		</div>

	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
			<div id="pro_tb">
				<div class="search-input">
					日期：
					<input id="fromDate" class="easyui-datebox" editable="false" style="width: 40%;" />
					~
					<input id="toDate" class="easyui-datebox" editable="false" style="width: 40%;" />
					
				</div>
				<div class="search-input text-right">
					<a href="#" class="d-btn btn-yellow" id="search">搜索</a>
					<a href="javascript:void(0)" class="d-btn btn-blue" onclick="newpro()">添加</a>
				</div>

			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var fromDate = ""; 
	var toDate = ""; 
	var goods =[[${goods}]];
	
	$(document).ready(function() {
		fromDate = getLastMonth().last;
		toDate = getLastMonth().now;
		$("#fromDate").datebox('setValue', fromDate);
		$("#toDate").datebox('setValue', toDate);
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
            pageSize: 10, 
			toolbar : '#pro_tb',
			url : "../goodscurrents",
			method : 'get',
			queryParams: {
				goodsid : goods.id,
				startdate : fromDate,
				enddate : toDate
			},
			onSelect : function(index, row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'name',
				title : '名称',
				width : '',
				formatter : function(value, row, index) {
					var html='';
					html += '<div class="info-unreviewed">';
					if(row.goods){
						html+= '<div class="info-item-name" style="width:'+ ellipsis2() +'px;">'+ row.goods.name +'</div>';
					}
					html += '<div class="info-time pr90">'+ formatDate(row.createdate) +'</div>'
					if(row.type==1){
						html += '<div class="info-percent">+'+ row.difference +'</div>'
					}else{
						html += '<div class="info-percent">-'+ row.difference +'</div>'
					}
					if(row.userinfo){
						html+= '<div class="info-content text-right">执行人：'+ row.userinfo.name +'</div>';
					}
					if (row.status == 4){
						html += '<div class="info-status ok">已审</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">已拒绝</div>';
					}
					if (row.status == 6){
						html += '<div class="info-status two">待二级审核</div>';
					}
					html+='</div>'
					return html;
				}
			} ] ]
		});
	});
	function ellipsis2(){
		var WIDTH = $("body").width();
		var width;
		width = WIDTH * 0.6;
		return width;
	}
	function refreshProTable() {
		$('#pro_table').datagrid('load',{
			goodsid : goods.id,
			startdate : fromDate,
			enddate : toDate
		});
	}
	
	$("#search").click(function(){
		fromDate = $("#fromDate").datebox('getValue');
		toDate = $("#toDate").datebox('getValue');
		refreshProTable();
	});

	function newpro() {
		window.location.href = "../app/goodscurrentadd.do?goodsid="+goods.id;
	}
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	function getLastMonth() {
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth() + 1;//0-11表示1-12月
		var day = now.getDate() + 1;
		var dateObj = {};
		dateObj.now = year + '-' + month + '-' + day;
		var nowMonthDay = new Date(year, month, 0).getDate(); //当前月的总天数
		if (month - 1 <= 0){ //如果是1月，年数往前推一年<br>　　　　 
			dateObj.last = (year - 1) + '-' + 12 + '-' + day;
		}else{
			var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();
			if (lastMonthDay < day){ //1个月前所在月的总天数小于现在的天日期
				if (day < nowMonthDay){ //当前天日期小于当前月总天数
					dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (nowMonthDay - day));
				}else{
					dateObj.last = year + '-' + (month - 1) + '-' + lastMonthDay;
				}
			}else{
				dateObj.last = year + '-' + (month - 1) + '-' + day;
			}
		}
		return dateObj;
	}
	function ellipsis2(){
		var WIDTH = $("body").width();
		var width;
		width = WIDTH-122 -10
		return width;
	}
</script>
</html>